package org.lq.er.util;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class AutoId {
	public static int getIdNo() {
		DataInputStream dis = null;
		DataOutputStream oos = null;
		int no = 10000;
		try {
			String dir = System.getProperty("user.dir");
			if(new File(dir+"/data/adminID.bat").exists()) {
				dis = new DataInputStream(new FileInputStream(dir+"/data/adminID.bat"));
				no = dis.read();
			}
			oos = new DataOutputStream(new FileOutputStream(dir+"/data/adminID.bat"));
			oos.writeLong(++no);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				oos.close();
				if(dis!=null) {
					dis.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return no;
	}
	public static void main(String[] args) {
		getIdNo();
	}
}
